const { Schema, SchemaTypes } = require('../schema');
const OrderStatus = require('../../module/const/OrderStatus');
const PaymentType = require('../../module/const/paymentType');
class Order extends Schema {
    PropertyModelDataTemplate () {
        return {
            areaId: { type: SchemaTypes.ObjectId, required: true },
            userId: { type: SchemaTypes.ObjectId, required: true },
            // 收货地址信息
            name: {
                type: SchemaTypes.String,
                required: true
            },
            phone: {
                type: SchemaTypes.String,
                required: true
            },
            area: {
                type: SchemaTypes.String,
                required: true
            },
            detailedAddress: {
                type: SchemaTypes.String,
                required: true
            },
            // 订单信息
            orderNo: {
                type: SchemaTypes.String,
                required: true,
                comment: '订单流水号'
            },
            productList: {
                type: SchemaTypes.Array,
                required: true,
                comment: '产品列表'
            },
            price: {
                type: SchemaTypes.Number,
                required: true,
                comment: '订单支付价格'
            },
            discount: {
                type: SchemaTypes.Number,
                required: true,
                comment: '折扣'
            },
            deliveryFee: {
                type: SchemaTypes.Number,
                required: false,
                comment: '配送费'
            },
            envelopeId: {
                type: SchemaTypes.ObjectId,
                required: false,
                comment: '红包id'
            },
            envelopeFee: {
                type: SchemaTypes.Number,
                required: false,
                comment: '红包抵扣金额'
            },
            coinCount: {
                type: SchemaTypes.Number,
                required: false,
                comment: '使用金币数'
            },
            status: {
                type: SchemaTypes.Number,
                required: true,
                default: OrderStatus.Committed.value,
                comment: '订单状态'
            },
            remark: {
                type: SchemaTypes.String,
                required: false,
                comment: '订单备注'
            },
            paymentMode: {
                type: SchemaTypes.String,
                required: true,
                default: PaymentType.wxPay,
                comment: '支付类型：信用金，微信支付'
            },

            // 支付相关字段
            prepayId: {
                type: SchemaTypes.String,
                required: false,
                comment: '微信支付预支付id'
            },
            payTime: {
                type: SchemaTypes.Number,
                required: false,
                comment: '支付时间'
            },
            paymentOrderId: {
                type: SchemaTypes.String,
                required: false,
                comment: '微信支付订单id'
            },
            // 退款相关字段
            refundId: {
                type: SchemaTypes.String,
                required: false,
                comment: '退款id'
            },
            refundOrderId: {
                type: SchemaTypes.String,
                required: false,
                comment: '退款id(更新支付之后)'
            },
            refundTime: {
                type: SchemaTypes.Number,
                required: false,
                comment: '退款时间'
            },
            refundDescribe: {
                type: SchemaTypes.String,
                required: false,
                comment: '退款描述'
            },
            // 订单业务状态转换时间
            deliveryTime: {
                type: SchemaTypes.Number,
                required: false,
                comment: '配送开始时间'
            },
            finishTime: {
                type: SchemaTypes.Number,
                required: false,
                comment: '订单完成时间'
            },
            cancelTime: {
                type: SchemaTypes.Number,
                required: false,
                comment: '订单取消时间'
            },

            // 版本号
            version: {
                type: SchemaTypes.String,
                required: false
            },
            createTime: {
                type: SchemaTypes.Number,
                required: true,
                default: require('../../module/tool/time').getCurrentTimestamp()
            },
            hasWxPayed: {
                type: SchemaTypes.Boolean,
                required: false,
                comment: '是否微信支付'
            }
        };
    }
}

module.exports = Order;
